package com.jit.monitor.base;

import com.jit.baselib.bean.response.BaseResponse;
import com.jit.monitor.commom.AppConstant;
import com.jit.monitor.model.response.LoginResponse;

import io.reactivex.Observable;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * @author crazyZhangxl on 2018/12/21.
 * Describe: 该retrofit请求自己添加请求头 不会默认添加
 */
public class ApiNormalRetrofit extends BaseClient {
    public MyApi mApi;
    private ApiNormalRetrofit(){
        mApi = new Retrofit.Builder()
                .baseUrl(MyApi.BASE_URL)
                .client(getClient())
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build()
                .create(MyApi.class);
    }

    private static  class  ApiNormalRetrofitHolder{
        private static final ApiNormalRetrofit HOLDER = new ApiNormalRetrofit();
    }

    public static ApiNormalRetrofit getInstance(){
        return  ApiNormalRetrofitHolder.HOLDER;
    }

    public Observable<BaseResponse> requestRegister(String username, String password){
        return mApi.requestRegister(username,password);
    }

    public Observable<BaseResponse<LoginResponse>> requestLogin(String username,String password){
        return mApi.requestLogin(AppConstant.BASE_TOKEN,username,password);
    }

}
